<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2019/3/8
 * Time: 10:45
 */
namespace app\index\controller;

use think\Controller;
use think\Db;
use think\Session;

class Suiniya extends controller{

    public function suiniya(){
        $res=db('suiya')
            ->join('f_user','f_suiya.uid=f_user.uid')
            ->field('f_suiya.*,f_user.uname,f_user.nickname,head_portrait,f_user.phone,f_user.avatars_img');
        $rs=db('suiya')
            ->join('f_user','f_suiya.uid=f_user.uid')
            ->count();
        $timestart='2019-01-01 15:34:40';
        $timeend=date("Y-m-d H:i:s");
        if (input('sub')){
            $times=input('start');
            $timee=input('end');
            if($times!=0){
                $timestart=$times." 23:59:59";
            }
            if($timee!=0){
                $timeend=$timee." 23:59:59";
            }
            $cateid=input('cateid');
            $sel=input('Key');
            $where = array();
            $where ['f_suiya.createtime'] = array("between",array($timestart,$timeend));
            switch ($cateid){
                case 'uname':
                    $where ['uname'] = array("like","%".$sel."%");
                    break;
                case 'id':
                    $where ['id'] = array("like","%".$sel."%");
                    break;
                case 'phone':
                    $where ['phone'] = array("like","%".$sel."%");
                    break;
                default :
                    $where ['uname'] = array("like","%".$sel."%");
                    break;
            }
            $res=db('suiya')
            ->join('f_user','f_suiya.uid=f_user.uid')
            ->where($where)
            ->paginate(5,false,['query'=>request()->param()]);//dump($res);die;
             
            $page=$res->render();
            $rs=db('suiya')->join('f_user','f_suiya.uid=f_user.uid')
                ->where($where)
                //S->where('f_suiya.createtime','between',[$timestart,$timeend])
                ->count();
            return view('suiniya',['res'=>$res,'rs'=>$rs,'page'=>$page]);
        }
        else
        {
            $res=db('suiya')
                ->join('f_user','f_suiya.uid=f_user.uid')
                ->field('f_suiya.*,f_user.uname,f_user.nickname,head_portrait,f_user.phone,f_user.avatars_img')
                ->paginate(8);
            $page=$res->render();
            return view('suiniya',['res'=>$res,'rs'=>$rs,'page'=>$page
                                  ]);
        }

    }
    public function updatesny(){
        $id=input('zid');
        $data=['flg'=>1];
        $rs=db('suiya')
            ->where('id',$id)
            ->update($data);
        if($rs){
            return 1;
        }else{
            return 0;
        }
    }
//    随你压设置
    public function suiniyashezhi(){
        if(request()->isAjax()){
            $date=["workdate"=>input('workdate'),"way"=>input('way'),"tel"=>input('tel')];
            $rs=db('suiyas')->where('id',1)->update($date);
            if($rs){
                return array('code'=>1,'msg'=>'成功'
                            );
            }
            else{
               return array('code'=>0,'msg'=>'失败');
            }
        }else{
           $res=db('suiyas')->find();
            return view('suiniyashezhi',['res'=>$res]);
        }

    }
}
